function [img, count, avail] = jstege_simple(img, msg)
    % JSTEGE_SIMPLE  Embed message using JSTEG.
    % [IMG, COUNT, AVAIL] = JSTEGE_SIMPLE(OIMG, MSG) embeds message MSG 
    % into image, and returns COUNT, the number of bits embeded and the
    % new image. IMG is JPEG DCT-coefs from jpeg_read().
    %
    
    bin = arrayToBinary(msg);
    data_size = size(bin,2);

    ROWS = size(img,1)/8;
    r = int16(im2vec(img, [8 8])');
    [M,N] = size(r);
    
    avail = countNonZeroOne(r);
    fprintf(1, 'avail = %db\n',avail);
    
    % hide every bit in BIN
    count = 1;
    p = 0;
    for j = 1:M
        if count > data_size
            break
        end
        for k = 1:N
            if count > data_size
                break
            end
            p = p + 1;
            v = r(j,k);
            % skip 0 & 1
            if (v == 0) || (v == 1)
                continue
            end
            % embed 1 bit
            if mod(v,2) ~= mod(bin(1,count),2)
                if mod(v,2) == 0
                    % 2 -> 3, -2 -> -1
                    r(j,k) = v + 1;
                else
                    % 3 -> 2, -1 -> -2
                    r(j,k) = v - 1;
                end
            end
            count = count + 1;
        end
    end
    
    count = count - 1;
    img = vec2im(double(r)', [0 0], [8 8], ROWS);

    % output
    if count < data_size
        len = floor((count-16)/8);
        fprintf(1, 'part of message hidden in whole image. %3.3f bpp, %3.3f bpc\n', count/M/N, count/avail);
        fprintf(1, ' msg = %dB (%db), %3.2f%%\n',len, count,100*count/data_size);
    else
        fprintf(1, 'whole message hidden in part of image. %3.3f bpp, %3.3f bpc\n', count/M/N, count/avail);
        fprintf(1, ' coef = %db, %3.2f%%\n',p,100*p/M/N);
    end
end
